package com.kanas.webak.config.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.kanas.framework.business.BusinessHandler;
import com.kanas.framework.business.ResponseMessage;
import com.kanas.framework.support.ControllerSupport;
import com.kanas.webak.config.domain.DictValue;
import com.kanas.webak.config.service.DictValueService;

@Controller
@RequestMapping("app/config/dictvalue")
public class DictValueController extends ControllerSupport {

	private DictValueService dictValueService;

	@RequestMapping(value="/new.html")
	public ModelAndView addNew(){
		ModelAndView mv=new ModelAndView();
		mv.setViewName("modules/config/dict_value_new");
		return mv;
	}
	
	@RequestMapping("new.do")
	public @ResponseBody ResponseMessage addNew(final DictValue dict) {
		ResponseMessage response = ResponseMessage.handleException(new BusinessHandler(){
			@Override
			public Object handle() throws Exception {
				return dictValueService.addNew(dict);
			}
		}, logger);
		return response;
	}
	
	@RequestMapping(value="/edit/{dictid}.html")
	public ModelAndView groupEditView(@PathVariable("dictid")String did){
		ModelAndView mv=new ModelAndView();
		mv.setViewName("modules/config/dict_value_edit");
		mv.addObject("dict", dictValueService.findOne(did));
		return mv;
	}
	
	@RequestMapping("update/edit.do")
	public @ResponseBody ResponseMessage update(final DictValue dict) {
		ResponseMessage response = ResponseMessage.handleException(new BusinessHandler(){
			@Override
			public Object handle() throws Exception {
				return dictValueService.update(dict);
			}
		}, logger);
		return response;
	}
	
	public DictValueService getDictValueService() {
		return dictValueService;
	}

	@Resource(name="com.kanas.webak.config.service.dictvalueservice")
	public void setDictValueService(DictValueService dictValueService) {
		this.dictValueService = dictValueService;
	}
}
